﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Sofire.AOP.Settings
{
    internal class AOPFilterSetting : AOPSettingBase
    {
        internal AOPFilterSetting() { }

        public AOPFilterSetting(string name, Type type)
        {
            if(string.IsNullOrEmpty(name)) throw new ArgumentNullException("name");
            if(type == null) throw new ArgumentNullException("type");

            this._Name = name;
            this._Type = type;
        }

        private string _Name;
        public string Name
        {
            get
            {
                return this._Name;
            }
        }

        private Type _Type;
        public Type Type
        {
            get
            {
                return this._Type;
            }
        }

        internal override void OnLoad(XmlNode node)
        {
            if(node == null) throw new ArgumentNullException("node");
            this._Name = node.TryGetAttribute("Name");
            var attrValue = node.TryGetAttribute("Type");

            if(string.IsNullOrEmpty(attrValue)) throw new ArgumentNullException("Type");
            this._Type = GetType(attrValue);

            if(this._Type == null) throw new ArgumentException("无法识别 " + this._Name + " 的类型 " + attrValue + " ！", "Type");
        }
    }

}
